Skip to content

Enclosing package p.q not visible as q #23069

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025

Conversation

som-snytt
Copy link
Contributor

@som-snytt som-snytt commented Apr 29, 2025

Fixes #23047

Normally, an enclosing definition always has higher "name binding" precedence than an import, but an enclosing packaging can have a dotted name with a simple name that can't be referenced without qualification or import.

This first cut gives up, but we can infer whether a package was introduced with a dotted name by comparing the owner of the current context with the enclosing package owner.

The second commit does that clever thing (which is not necessarily a good thing).

The final cut just relies on "finding the p.q in an enclosing context", just like any definition. An actual definition may have a position in a different file (which is lower precedence); but an enclosing definition or an enclosing package clause which is unpositioned can only be in the current file.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch 3 times, most recently from fca2ca4 to 05fc3cd Compare April 30, 2025 03:06
@som-snytt
Copy link
Contributor Author

It's been a while since I ran the lint on the dotty code base.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch from 05fc3cd to bea7edc Compare April 30, 2025 23:23
@@ -419,7 +419,7 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
candidate = cur
importer = sel
else if checkMember(cur.owner) then
if sym.srcPos.sourcePos.source == ctx.source then
if sym.is(Package) || sym.srcPos.sourcePos.source == ctx.source then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package sym has no source to compare.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch from bea7edc to 06d1611 Compare April 30, 2025 23:29
@som-snytt som-snytt marked this pull request as ready for review May 1, 2025 03:35
@Gedochao Gedochao requested a review from sjrd May 5, 2025 06:10
Copy link
Member

@sjrd sjrd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Do you want to keep the 3 commits? From the looks of it, the whole diff is a lot smaller than the individual commits.

@som-snytt som-snytt force-pushed the issue/23047-pkg-import branch from 06d1611 to e392382 Compare May 5, 2025 14:59
@som-snytt
Copy link
Contributor Author

I need one commit for my semester project, another for my master's, and the last for the published paper.

@sjrd sjrd enabled auto-merge May 5, 2025 15:08
@sjrd sjrd merged commit d87bbb1 into scala:main May 5, 2025
29 checks passed
@som-snytt som-snytt deleted the issue/23047-pkg-import branch May 5, 2025 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

False positive warning: Unused import of a package
2 participants